package com.xc.controller.protol;

import com.xc.common.ServerResponse;
import com.xc.service.IUserWithdrawService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/20 11:12 AM
 */
@Controller
@RequestMapping("/user/withdraw/")
@Slf4j
public class UserWithdrawController {

    @Autowired
    IUserWithdrawService iUserWithdrawService;


    /**
     *  查询用户提现记录
     * @param pageNum
     * @param pageSize
     * @param withStatus
     * @param request
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "8") int pageSize,
                                  @RequestParam(value = "withStatus",required = false) String withStatus,
                                  HttpServletRequest request){
        return iUserWithdrawService.findUserWithList(withStatus,request,pageNum,pageSize);
    }


    /**
     * 发起提现订单
      */
    @RequestMapping("outMoney.do")
    @ResponseBody
    public ServerResponse outMoney(String amt,HttpServletRequest request){
        ServerResponse serverResponse = null;
        try {
            serverResponse = iUserWithdrawService.outMoney(amt , request);
        }catch (Exception e){
            log.error("出金异常 e = {}" , e);
            serverResponse = ServerResponse.createByErrorMsg("出金异常，请稍后再试");
        }
        return serverResponse;
    }

    /**
     *  用户主动撤销提现接口
     * @param withId
     * @return
     */
    @RequestMapping("cancel.do")
    @ResponseBody
    public ServerResponse userCancel(Integer withId){
        return iUserWithdrawService.userCancel(withId);
    }




}
